package com.woniuxy.dr_mall.controller;


import com.woniuxy.dr_mall.entity.MyResponseEntity;
import com.woniuxy.dr_mall.service.IDrRegionService;
import org.springframework.beans.factory.annotation.Autowired;
import com.woniuxy.dr_mall.entity.DrRegion;
import org.springframework.web.bind.annotation.*;


import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 张哲轩
 * @since 2021-08-11
 */
@RestController
@RequestMapping("/dr_mall/drRegion")
public class DrRegionController {
    @Autowired
    private IDrRegionService iDrRegionService;

    @GetMapping("getProvince")
    public MyResponseEntity getProv(){
        List<DrRegion> provinces = iDrRegionService.getProvince();
        MyResponseEntity myResponseEntity = new MyResponseEntity();
        myResponseEntity.setCode(MyResponseEntity.SUCCESS.getCode());
        myResponseEntity.setMsg("省列表查询");
        myResponseEntity.setData(provinces);

        return myResponseEntity;
    }

    @GetMapping("getByPid/{id}")
    public MyResponseEntity getByPid(@PathVariable Integer id){
        if (id == '0' || id == null){

        }
        List<DrRegion> provinces = iDrRegionService.getByPid(id);
        MyResponseEntity myResponseEntity = new MyResponseEntity();
        myResponseEntity.setCode(MyResponseEntity.SUCCESS.getCode());
        myResponseEntity.setData(provinces);

        return myResponseEntity;
    }

    //根据pid查询所有的省份信息
    @GetMapping("initial")
    public MyResponseEntity usePidSelectRegion(int pid){

        return new MyResponseEntity(iDrRegionService.usePidSelect(pid));
    }
}

